﻿using ToolKitIESiteList.Library;
using System;
using System.Windows.Forms;

namespace ToolKitManagerIESiteList
{
    public partial class FrmChangeVersion : Form
    {
        public FrmChangeVersion()
        {
            InitializeComponent();
        }

        private void BntOk_Click(object sender, EventArgs e)
        {
            int newversion;
            if (!int.TryParse(TxtNewVersion.Text, out newversion))
            {
                newversion = EmieDocument.VersionEmieDocument;
            }
            var oldver = EmieDocument.VersionEmieDocument;
            EmieDocument.UpdateVersionEmieDocument(newversion);
            ManagerHotTracker.AddTraker(ActionTracker.ChangeVersion, Properties.Resources.ChangedVersion,string.Format("{0} => {1}", oldver,EmieDocument.VersionEmieDocument), null);
            this.DialogResult = DialogResult.Cancel;
            if (oldver != newversion)
            {
                this.DialogResult = DialogResult.OK;
            }
            Close();
        }

        private void BntCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            Close();
        }

        private void FrmChangeVersion_Load(object sender, EventArgs e)
        {
            TxtNewVersion.Text = EmieDocument.VersionEmieDocument.ToString();
            UCVersion.TextLabel = TxtNewVersion.Text;
        }

        private void FrmChangeVersion_Shown(object sender, EventArgs e)
        {
            TxtNewVersion.Focus();
        }

        private void TxtNewVersion_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }
    }
}
